<template>
	<view class="pb">
		<view class="search-nav">
			<view><uni-search-bar placeholder="搜索内容" radius="8" bgColor="#FFFFFF" @confirm="onSearch" @clear="onCancel" cancelButton="none" @input="onInput" /></view>
			<view class="p10-0">
				<text class="searchBtn" @click="onSearchBtn">搜索</text>
			</view>
		</view>
		<view class="p0-8">
			<scroll-view class="scroll-view_H" scroll-x="true" scroll-left="120">
				<view v-for="item in infoType" :key='item.title' class="scroll-view-item_H">
					<view :class="form.type == item.id ? 'tabs_' : 'tabs'" @click="onSelectType(item.id)">{{item.title}}</view>
				</view>
			</scroll-view>
		</view>
		<uni-list>
			<uni-list-item v-for="item in dataInfo" :key='item.id' ellipsis="2" :title="item.title" :note="item.addr" :thumb="item.log" thumb-size="lg" >
				<template v-slot:footer>
					<uni-tag @click="onLink('/pages/cooperation/info/info',item.id)" class="mt20" text="了解详情" type="warning" :circle="true" />
				</template>
			</uni-list-item>
		</uni-list>
		
		<view class="fixed-bottom">
			<view class="p0-8"><button class="default-button-push" @click="onCustomer">加入我们</button></view>
		</view>
		
		<uni-popup ref="popupCustomer" background-color="none">
			<customerVue></customerVue>
		</uni-popup>
		
	</view>
</template>

<script>
	import customerVue from '../../components/customer.vue'
	export default {
		components: {
			customerVue
		},
		data() {
			return {
				form:{page:1,type:0,title:'',limit:20},
				dataInfo:[],
				infoType:[]
			}
		},
		onShow() {
			this.onGetData()
		},
		methods: {
			onGetData(){
				let _this = this
				this.$request_api('applet_api/resources','POST',_this.form).then(res => {
					_this.dataInfo = res.data
					_this.infoType = _this.mapType(res.types)
				}).catch(err => {
					console.log(err)
				})
			},
			onSelectType(id){
				this.form.type = id
				this.onGetData()
			},
			onSearch(e){
				this.form.title = e.value
				this.form.page = 1
				this.dataInfo = []
				this.onGetData()
			},
			onInput(e){
				this.form.title = e
			},
			onSearchBtn(){
				this.form.page = 1
				this.dataInfo = []
				this.onGetData()
			},
			onCancel(e){
				this.form.title = ''
				this.form.page = 1
				this.dataInfo = []
				this.onGetData()
			},
			mapType(data){
				let obj = { title: '全部', id: 0 }
				data.unshift(obj)
				return data.map((item) => {
					item.text = item.title
					item.value = item.id
					return item
				});
			},
			onLink(url,id){
				uni.navigateTo({
					url: url+"?id="+id
				});
			},
			onCustomer(){
				this.$refs.popupCustomer.open('center')
			}
		}
	}
</script>

<style scoped lang="scss">
</style>
